package cn.edu.zafu.bigdata.x.wupeng.i;

public class TheadDemo3 {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("Main Start");
        Thread t = new MyThread4();
        t.start();
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t.interrupt();
        t.join();
        System.out.println("Main End");
    }
}

class MyThread4 extends Thread {
    public void run() {
        Thread hello = new HelloThread();
        hello.start(); // 启动hello线程
        try {
            hello.join(); // 等待hello线程结束
        } catch (InterruptedException e) {
            System.out.println("interrupted!");
        }
            hello.interrupt();

    }
}
class HelloThread extends Thread {
    public void run() {
        int n = 0;
        while (!isInterrupted()) {
            n++;
            System.out.println(n + " hello!");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                break;
            }
        }
    }
}